# -*- coding: utf-8 -*-
# @Time    : 2021/4/24 9:23
# @Author  : lilu
# @Email   : 1906196327@qq.com
# @File    : 作业.py
# @Software: PyCharm

########## filter 过滤出规范的用户名
import  re
usernames = ["123wrdwf_","qwef676_jaidh","uhgiu_6678uiqghdui","tygh7654_","a12346fu_de"]
def user(x):
    # for i in x:
        ret = re.match(r"^[a-zA-Z_]\w{5,17}$",x)
        if 6 <= len(x) <= 18 and ret:
            print(f"{x}符合密码规范！")
        else:
            print(f"{x}密码不符合规范！")

result = filter(user,usernames)
print(list(result))


########## 匿名函数+reduce 实现1*2*3...*n
from functools import reduce
n = int(input("请输入一个数字实现数字的累乘："))
result = reduce(lambda x, y: x*y,range(1,n))
print(result)


############ 使用filter函数，将100以内能被3整除的数
result = filter(lambda x: x%3 == 0,range(1,101))
print(list(result))


########### map函数求list[1-10]内各数的平方
result = map(lambda x : x*x,range(1,11))
print(list(result))

########### 将[1,2,3,4,5]转换为12345
result = reduce(lambda x,y: str(x)+str(y),[1,2,3,4,5])
print(result)

############### 有以下列表：list[7,-8,5,4,0,-2,-5]
# 正数在前负数在后，整数从小到大，负数从大到小
lis = [7,-8,5,4,0,-2,-5]
lis1 = []
lis2 = []
for i in lis:
    if i <= 0:
        lis1.append(i)
    else:
        lis2.append(i)
result1 = sorted(lis1,reverse=True)
result2 = sorted(lis2)
print(list(result2)+list(result1))


############## 一个字符串的排序：小写<大写<奇数<偶数
# s= 'asdf234GDSdsf23' # 排序小写-大写-奇数-偶数
# 原理：先比较元组的第一个值，false
s = 'asdf234GDSdsf23'
num = [] #数字列表
agr = '' #字母字符串
for i in s :
    if i.isdigit():
        num += i
    else:
        agr += i

c = [x for x in num if int(x)%2 == 0] #偶数
a = [x for x in num if int(x)%2 != 0] #奇数
a.extend(c) #奇数在前偶数在后

result1 = sorted(agr,reverse=True) #字母进行排序，小写字母在前大写字母在后
for i in list(result1+a):
    print(i,end="")